package cn.itsource.user.controller;

import cn.itsource.basic.exception.BusinessException;
import cn.itsource.basic.util.AjaxResult;
import cn.itsource.user.service.IVerifyCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/verifycode")
public class VerifyCodeController {

    @Autowired
    private IVerifyCodeService verifyCodeService;
    //一定情况下Map能够代替类使用
    @PostMapping("/smsCode") //注册验证码
    public AjaxResult sendSmsCode(@RequestBody Map<String,String> params){
        String phone = params.get("phone");
        String type = params.get("type"); //register binder login
        try {
            verifyCodeService.sendSmsCode(params);
            return AjaxResult.me();
        }
        catch (BusinessException e){
            e.printStackTrace();
            return AjaxResult.me().setMessage("发送失败!"+e.getMessage());
        }
        catch (Exception e) {
            return AjaxResult.me().setMessage("系统错误!"+e.getMessage());
        }
    }
}
